package com.shihb.chapter07designpattern.observer

import scala.collection.mutable.ListBuffer

/**
 * Description:
 *
 * @author shihb
 * @date 2020/10/4 10:39
 */
class WeatherStation extends SubObserver {
  val obserbers: ListBuffer[Obserber] = ListBuffer[Obserber]()
  var weather = "今天天气晴"
  override def registerObserver(obserber: Obserber): Unit = obserbers+=obserber

  override def removeObserver(obserber: Obserber): Unit = if (obserbers.contains(obserber)) obserbers-=obserber

  def set(msg:String): Unit ={
    this.weather=msg
    this.notificationObserver()
  }

  override def notificationObserver(): Unit = {
    obserbers.foreach(_.update(weather))
  }
}
